﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V5_Model;
using System.Data;
using V5_Common;
using V5_DAL.SqlServer;

namespace V5_BLL {
    public class BLLGZProductClass {
        private readonly DALGZProductClass dal = new DALGZProductClass();
        public BLLGZProductClass() { }
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public string GetMaxId() {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(Guid ClassID) {
            return dal.Exists(ClassID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(ModelGZProductClass model) {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ModelGZProductClass model) {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(Guid ClassID) {

            return dal.Delete(ClassID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ModelGZProductClass GetModel(Guid ClassID) {

            return dal.GetModel(ClassID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere) {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder) {
            return dal.GetList(Top, strWhere, filedOrder);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList() {
            return GetList("");
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        /// <param name="what"></param>
        /// <param name="Top"></param>
        /// <param name="strWhere"></param>
        /// <param name="filedOrder"></param>
        /// <returns></returns>
        public DataSet GetList(string what, int Top, string strWhere, string filedOrder) {
            return dal.GetList(what, Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere, string strOrder, ref int RecordCount) {
            return dal.GetList(PageSize, PageIndex, strWhere, strOrder, ref RecordCount);
        }
        #endregion  Method


        public DataTable GetDropDownList(int ChannelID, string strMsg) {
            //List<ModelGZProductClass> listClass = this.GetModelList(" Order by ClassCode ");
            DataTable dtListClass = dal.GetList(" Order by ClassCode ").Tables[0];
            DataTable dropdt = new DataTable();
            dropdt.Columns.Add("ClassID");
            dropdt.Columns.Add("ClassName");
            if (strMsg.Trim() != "") {
                DataRow dr = dropdt.NewRow();
                dr["ClassID"] = "0";
                dr["ClassName"] = strMsg;
                dropdt.Rows.Add(dr);
            }
            if (dtListClass != null) {
                foreach (DataRow drC in dtListClass.Rows) {
                    DataRow dr = dropdt.NewRow();
                    dr["ClassID"] = drC["ID"].ToString();
                    dr["ClassName"] = GetColumnListName(drC["TypeName"].ToString(), drC["ClassCode"].ToString());
                    dropdt.Rows.Add(dr);
                }
            }
            return dropdt;
        }

        public string GetColumnListName(string sName, string sCode) {
            int Level = (sCode.Length / 4 - 1) * 2;
            string sStr = sCode.Length == 4 ? "" : "├";
            if (Level > 0) {
                for (int i = 0; i < Level; i++)
                    sStr += "－";
            }
            return sStr + sName;
        }

        public void MoveClass(Guid ClassID, int isUp) {

        }
    }
}
